﻿//<script type="text/javascript">
function $(_sId){
	return document.getElementById(_sId);
};

var type_=0;//默认为超级连接
var selectstr="";//选中的字符串
var window_;
function GetRound()
{
     var i_N = Math.round(Math.random() * 9999);//0-9999
     return i_N;
}
function showcliclcolor()
{
    var obj_cllist=$("html_color").childNodes;
    for(var i=0; i<obj_cllist.length; i++)
    {
        var iobj_=obj_cllist[i];
        iobj_.unselectable="On";
        iobj_.onclick=function()
        {
            colorClick(this);
        };
    }
}

function imgoverout(img_,over_out)
{
    var imgpar_=img_.src.toString().toLowerCase();
    var imgpar0_=imgpar_.split('/');
    var imgname_=imgpar0_[imgpar0_.length-1];
    if (over_out==0)//over
    {
        img_.src=imgpar_.replace(".jpg","1.jpg");
    }
    else//out
    {
        img_.src=imgpar_.replace("1.jpg",".jpg");
    }
}
function colorOver(theTD) 
{
//    previewColor(theTD.style.backgroundColor);
//    setTextField(theTD.style.backgroundColor);
}   
function colorClick(theTD) {
    FormatText("ForeColor", theTD.style.backgroundColor);
}
function setTextField(ColorString) {
//document.getElementById("ColorText").value = ColorString.toUpperCase();
}
function returnColor(ColorString) {
    return ColorString;	
}		
function userInput(theinput) {
    previewColor(theinput.value);
}
function previewColor(theColor) 
{
    try {
    PreviewDiv.style.backgroundColor = theColor;
    } catch (e) {}
}
    
function setMode(newMode)
{
  bTextMode = newMode;
  var cont;
  if (bTextMode) {
    cleanHtml();
    cleanHtml();

    cont=message.document.body.innerHTML;
    message.document.body.innerText=cont;
  } else {
    cont=message.document.body.innerText;
    message.document.body.innerHTML=cont;
  }
  message.focus();
}
function cleanHtml()
{
  var fonts = message.document.body.all.tags("FONT");
  var curr;
  for (var i = fonts.length - 1; i >= 0; i--) {
    curr = fonts[i];
    if (curr.style.backgroundColor == "#ffffff") curr.outerHTML	= curr.innerHTML;
  }

}
function FormatText(command, option){
	frames.message.focus();
  	frames.message.document.execCommand(command, true, option);
  	frames.message.focus();
}
//Function to add image
function AddImage(imgname_){
    frames.message.focus();
    var url_=document.getElementById("html_dxa").src.toString().toLowerCase().replace('dx.jpg','');//取得图片地址				
	
	if (imgname_ != null){
	    var nurl=url_+imgname_+".gif";	
		frames.message.document.execCommand('InsertImage', false, nurl);
  		frames.message.focus();
	}
	frames.message.focus();		
}
function article_preview(){
	var editor_win = window.open('', "_blank", '');
		editor_win.document.open('text/html', 'replace');
		editor_win.opener = null 
		editor_win.document.writeln(frames.message.document.body.innerHTML);
		editor_win.document.close();
}
function showifr(te_)
{
    type_=te_;
    //url_=path_+"img.htm?id="+te_+"&k="+GetRound();
    
    if(type_==0)//超级链接
    {
        url_=path_+"link.htm?k="+GetRound();
        window_=window.showModalDialog(url_, window, "dialogWidth: 300px; dialogHeight: 150px; help: no; scroll: no; status: no");
    }
    else if(type_==1)//插入图片
    {
        addimgs();
//        url_=path_+"AddImg/ImgIfr.aspx?k="+GetRound();
//        window_=window.showModalDialog(url_, window, "dialogWidth: 590px; dialogHeight: 490px; help: no; scroll: no; status: no");
//        if (window_ != null && window_!="")
//        {
//            var oRTE = frames.message;
//            try{
//	            oRTE.focus();
//	            var oRng = oRTE.document.selection.createRange();
//	            oRng.pasteHTML(window_);
//	            oRng.collapse(false);
//	            oRng.select();
//            }
//            catch(e){}
//        }
    }
    else if(type_==2)//插入动画
    {
        url_=path_+"AddFlash/FlashIfr.aspx?k="+GetRound();
    }
    else if(type_==4)
    {
        url_=path_+"mp3.htm?k="+GetRound();
        window_=window.showModalDialog(url_, window, "dialogWidth: 300px; dialogHeight: 170px; help: no; scroll: no; status: no");
    }
    

}
function addhtmlobj(rvl_)
{
    if (type_==0)//超级连接
    {
        var oRTE = frames.message;
        //alert(rvl_+"/"+type_);
   		try{
			var html = "<a href='" + rvl_ + "' target='_blank'>" + selectstr + "</a>";
			oRTE.focus();
			var oRng = oRTE.document.selection.createRange();
			oRng.pasteHTML(html);
			oRng.collapse(false);
			oRng.select();
		}catch(e){}
    }
    else if (type_==1)//插入图片
    {
        	var oRTE = frames.message;
		    var html = "<img src='" + rvl_ + "'>";
			try{
				oRTE.focus();
				var oRng = oRTE.document.selection.createRange();
				oRng.pasteHTML(html);
				oRng.collapse(false);
				oRng.select();
			}
			catch(e){}
    }
    else//动画功视频
    {
        	var oRTE = frames.message;
		    var html = "<embed src='"+rvl_+"' ></embed>";
			try{
				oRTE.focus();
				var oRng = oRTE.document.selection.createRange();
				oRng.pasteHTML(html);
				oRng.collapse(false);
				oRng.select();
			}
			catch(e){}
    }
}



//</script>
//<script type="text/javascript">
var FontMenuFuncHash = {
	menulist: {
		html_t: {obj: "html_dx"},
		html_a: {obj: "html_zt"},
		html_aa: {obj: "html_color"},
		html_dxa: {obj: "html_bq"}		
	},
	click: function (el, _tthis) 
	{
		var node;
		var event = window.event || el;
		var esrc = event.srcElement || event.target;
		var obj_ctl;
		
		for(var key in _tthis.menulist) 
		{
			node =_tthis.menulist[key];
			obj_ctl=$(node["obj"]); 
			if(esrc.getAttribute("action") == key) 
			{
				    if(obj_ctl.style.display == "block") 
				    {
					    obj_ctl.style.display = "none";
				    }
				    else 
				    {
					    obj_ctl.style.display = "block";
					    showxy_(obj_ctl,event);
				    }
			}
			else 
			{
				obj_ctl.style.display = "none";
			}
			
			
		}
		
		//alert("click");
	},
	hide: function (event, _this) 
	{
		var node;
		var obj_ctl;
		for(var key in _this.menulist) 
		{
			node = _this.menulist[key];
			obj_ctl=$(node["obj"]);   
			obj_ctl.style.display = "none";
		};
		
		//alert("hide");
	}
};
function addat()
{
    $("html_dh").onclick =$("html_tp").onclick =$("html_tb").onclick =$("html_srka").onclick =$("html_dxa").onclick = $("html_aa").onclick =$("html_a").onclick  =$("html_t").onclick=$("html_mp3").onclick  = function (event) 
    {
	    FontMenuFuncHash.click(event, FontMenuFuncHash);
	    
	    event = event || window.event;
	    event.cancelBubble = true;
    	
	    var rng;
	    var selection = frames.message.document.selection; 
	    if (selection != null) {
		    rng = selection.createRange();
	    }
	    selectstr = rng.text ? rng.text : "";
    	
	    var sid_=this.id
	    if (sid_=="html_srka")
        {
            showifr(0);
        }
        else if (sid_=="html_tb")
        {
            showifr(3);
        }
        else if (sid_=="html_tp")
        {
            showifr(1);
        }
        else if (sid_=="html_dh")
        {
            showifr(2);
        }
        else if(sid_=="html_mp3")
        {
            showifr(4);
        }
    };
    $("message").contentWindow.document.onclick =document.onclick = function (event) {
	    event = event || window.event;
	    FontMenuFuncHash.hide(event, FontMenuFuncHash);
    };
}

function showxy_(obj__,event){//显示DIV
    var esrc = event.srcElement || event.target;
//    if (esrc.tagName.toLowerCase()=="img")
//    {
       var ttop=document.body.scrollTop>document.documentElement.scrollTop?document.body.scrollTop:document.documentElement.scrollTop;
       
       obj__.style.left=document.documentElement.scrollLeft+event.clientX-event.offsetX+esrc.width-28;
       //obj__.style.top=document.documentElement.scrollTop+event.clientY-event.offsetY+20;
       obj__.style.top=ttop+event.clientY-event.offsetY+20;
//    }
//    else
//    {
//       this.RppDiv().style.left=document.documentElement.scrollLeft+event.clientX-event.offsetX+25;
//       this.RppDiv().style.top=document.documentElement.scrollTop+event.clientY-event.offsetY+20; 
//   }
}

function showstyle()
{/*
scrollbar-face-color: #fff;
scrollbar-highlight-color: #c1c1bb;
scrollbar-shadow-color: #c1c1bb;
scrollbar-3dlight-color: #ebebe4;
scrollbar-arrow-color: #cacab7;
scrollbar-track-color: #f4f4f0;
scrollbar-darkshadow-color: #ebebe4;
	*/

    try{

        frames.message.document.body.style.scrollbarFaceColor="#fff";
        frames.message.document.body.style.scrollbarHighlightColor="#c1c1bb";
        frames.message.document.body.style.scrollbarShowdowColor="#c1c1bb";
        frames.message.document.body.style.scrollbar3dlightColor="#ebebe4";
        frames.message.document.body.style.scrollbarArrowColor="#cacab7";
        frames.message.document.body.style.scrollbarTrackColor="#f4f4f0";
        frames.message.document.body.style.scrollbarDarkshadowColor="#ebebe4";
    }
    catch(e)
    {
        showstyle();
    }
}
//showstyle();

function showcolor() {
	var onrow=1;
	var oncol=1;
	var count=1;
	var s ="";
	var set1 = "";
	var set2 = "";
	for (var r=5; r>=0; r--) {
		for (var g=5; g>=0; g--) {
			for (var b=5; b>=0; b--) {
				//if (oncol==1) s += "\n";
				//s += "<div onmouseover=\"colorOver(this);\" onclick=\"colorClick(this);\" style=\"background-color:"+ReturnHex(r)+ReturnHex(g)+ReturnHex(b)+";\" class='html_cc'></div>";
				s+="<div class='html_cc'  style='background-color:"+ReturnHex(r)+ReturnHex(g)+ReturnHex(b)+"'  onclick='colorClick(this)'  unselectable='on'></div>";
				oncol++;
                if (oncol >= 19)
                {
                    oncol = 1;

                    if (onrow % 2 == 0)
                    {
                        set2 += s;
                    }
                    else
                    {
                        set1 += s;
                    }
                    s = "";
                    onrow++;
                }				
				count++;
			}
		}
	}
   document.getElementById("html_color").innerHTML=set1+set2+"<div style='clear: both;'></div>";
}

function ReturnHex(i) {
	switch (i) {
		default:
		case 0:
			return "00";
		case 1:
			return "33";
		case 2:
			return "66";
		case 3:
			return "99";			
		case 4:
			return "CC";
		case 5:
			return "FF";			
	}
}

function showimg()
{
    for(var i=0;i<20;i++)
    {
        var temp_= "<img src='"+path_+"images/"+i+".gif' width='24' height='24' onClick='AddImage("+i+");' unselectable='on'>";
        $("html_bq").insertAdjacentHTML("beforeEnd",temp_);
    }
}
 function SaveContent(){
//    try{
        if($(html_id_ctlid).value!=frames.message.document.body.innerHTML){
	           $(html_id_ctlid).value=frames.message.document.body.innerHTML
        }
//    }catch(e){}
}
function LoadContent(html_id_ctlid_){
//    try{
        frames.message.document.body.innerHTML=document.getElementById(html_id_ctlid_).value;
//    }catch(e){}
    setInterval("SaveContent()",100);
}
function RIfrBodyHtml()
{
   var url_001="http://"+window.location.toString().toLowerCase().split('/')[2];//取得网站地址
   
   var u_0="src="+url_001;
   var u_1="src='"+url_001;
   var u_2='src="'+url_001;
   
   var reg0 = new RegExp("("+u_0+")","g");
   var reg1 = new RegExp("("+u_1+")","g");
   var reg2 = new RegExp("("+u_2+")","g");
   

    var rhtml_= document.getElementById(html_id_ctlid).value.toLowerCase();
    rhtml_=rhtml_.replace(reg0,'src=');
    rhtml_=rhtml_.replace(reg1,"src='");
    rhtml_=rhtml_.replace(reg2,'src="');
    
    return rhtml_;
}
//LoadContent();
//showimg();
//showcliclcolor();
//</script>